#include "Query.h"

Query::Query(int d){
        D = d;
        p.setDimension(d);
    }

//Calculate and return euclidean distance between two points
double Query::euclideandistance(point a, point b){
        double sumofdifsquare=0.0;
        for(int i=0; i< sizeof(a.values)/sizeof(double); i++){
            sumofdifsquare = sumofdifsquare + pow((a.values[i] - b.values[i]),2);
        }
        return  sqrt(sumofdifsquare);
    }


//Find and return KNN for a given query and k
list<Query::pointk> Query::pyramidKNN(Query::point q, int k){
       list<pointk> A;
       double dmax=0.0;
       //Find the pyramid number and its height.
       Pyramid::pyrval pv;
       pv=p.pyramidvalue(q.values);
       //TODO
       //node -<LocateLeaf(B+tree,q)
       //SearchLeft(node,A,q,pv.pyramid)
       //SearchRight(node,A,q,pv.pyramid+0.5)
       A.sort();
       //dmax=euclideandistance(A[0],q)
       //Generate W centered at q with delta <- 2dmax
       for(int j=0; j< 2*D; j++){
           if(j!= pv.pyramid) //&& (W intersects pyramid j){
           {
               //PyramidRangeSearch(B+tree, W, q, A)
               //Update W with updated delta <-2dmax
           }

       }
       return A;

    }

//Perform a point search for a given point
bool Query::pyramidpointsearch(point a){
    //Find the pyramid number and height
    Pyramid::pyrval pv;
    p.pyramidvalue(a.values);
    //Use the pyramid value to search B++ tree and return true if it is found
    return 0;
}

//Performs a range search on the qiven query  and returns the ponts found. Functiona input parameter qr, is a [D][2]- dimensional array. For each dimension it has lower and higher range values.
Query::point * Query::pyramidrangesearch(double qr[][2]){
    Pyramid::queryrange pyrqr[2*D];
   // pyrqr = p.getqueryrange(qr);
    //Search B+-tree with all the pyramid values and return the points found
    Query::point p[10];
    return p;
}


